﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.CompilerServices;
using AutoR.Models;
using AutoR.Services;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;

namespace AutoR.ViewModels.Tasks
{
	// Token: 0x02000081 RID: 129
	public class ShipMultiSelectViewModel : BindableBase, INavigationAware, INavigatedAware, INavigatingAware
	{
		// Token: 0x17000081 RID: 129
		// (get) Token: 0x0600022D RID: 557 RVA: 0x00045A76 File Offset: 0x00043C76
		private INavigationService NavigationService { get; }

		// Token: 0x17000082 RID: 130
		// (get) Token: 0x0600022E RID: 558 RVA: 0x000408F6 File Offset: 0x0003EAF6
		public GameData Game
		{
			get
			{
				return Runtime.Game;
			}
		}

		// Token: 0x17000083 RID: 131
		// (get) Token: 0x0600022F RID: 559 RVA: 0x00045A7E File Offset: 0x00043C7E
		public DelegateCommand<ShipSelectItem> ChangeCommand { get; }

		// Token: 0x17000084 RID: 132
		// (get) Token: 0x06000230 RID: 560 RVA: 0x00045A86 File Offset: 0x00043C86
		// (set) Token: 0x06000231 RID: 561 RVA: 0x00045A90 File Offset: 0x00043C90
		public int ShipType
		{
			[CompilerGenerated]
			get
			{
				return this.<ShipType>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<ShipType>k__BackingField == value)
				{
					return;
				}
				this.<ShipType>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.ShipType);
			}
		}

		// Token: 0x17000085 RID: 133
		// (get) Token: 0x06000232 RID: 562 RVA: 0x00045ABD File Offset: 0x00043CBD
		// (set) Token: 0x06000233 RID: 563 RVA: 0x00045AC8 File Offset: 0x00043CC8
		public IList<int> sourceList
		{
			[CompilerGenerated]
			get
			{
				return this.<sourceList>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<sourceList>k__BackingField, value))
				{
					return;
				}
				this.<sourceList>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.sourceList);
			}
		}

		// Token: 0x17000086 RID: 134
		// (get) Token: 0x06000234 RID: 564 RVA: 0x00045AF8 File Offset: 0x00043CF8
		// (set) Token: 0x06000235 RID: 565 RVA: 0x00045B00 File Offset: 0x00043D00
		public ObservableCollection<ShipSelectItem> List
		{
			[CompilerGenerated]
			get
			{
				return this.<List>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<List>k__BackingField, value))
				{
					return;
				}
				this.<List>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.List);
			}
		}

		// Token: 0x06000236 RID: 566 RVA: 0x00045B30 File Offset: 0x00043D30
		public ShipMultiSelectViewModel(INavigationService navigationService)
		{
			this.<List>k__BackingField = new ObservableCollection<ShipSelectItem>();
			base..ctor();
			this.NavigationService = navigationService;
			this.ChangeCommand = new DelegateCommand<ShipSelectItem>(new Action<ShipSelectItem>(this.OnChangeCommandExecuted));
		}

		// Token: 0x06000237 RID: 567 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatedFrom(INavigationParameters parameters)
		{
		}

		// Token: 0x06000238 RID: 568 RVA: 0x00045B64 File Offset: 0x00043D64
		public void OnNavigatedTo(INavigationParameters parameters)
		{
			if (parameters.ContainsKey("list"))
			{
				this.sourceList = (IList<int>)parameters["list"];
				this._mode = "list";
			}
			if (parameters.ContainsKey("stlist"))
			{
				this.sourceList = (IList<int>)parameters["stlist"];
				this._mode = "stlist";
			}
			this.GenList();
		}

		// Token: 0x06000239 RID: 569 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatingTo(INavigationParameters parameters)
		{
		}

		// Token: 0x0600023A RID: 570 RVA: 0x00045BD4 File Offset: 0x00043DD4
		public void GenList()
		{
			if (this.sourceList == null)
			{
				return;
			}
			List<UserShip> list = this.Game.UserShip.ToList<UserShip>();
			if (this._mode == "stlist")
			{
				list = (from i in this.Game.UserShip
				where i.IsNeedStrengthen
				select i).ToList<UserShip>();
			}
			if (this.ShipType != 0)
			{
				int[] id = new int[]
				{
					0,
					1,
					2,
					3,
					4,
					5,
					6,
					7,
					8,
					9,
					10,
					11,
					12,
					13,
					14,
					15,
					16,
					23,
					24
				};
				list = (from i in list
				where i.Type == (ShipType)id[this.ShipType]
				select i).ToList<UserShip>();
			}
			List<ShipSelectItem> list2 = new List<ShipSelectItem>();
			foreach (UserShip userShip in list)
			{
				list2.Add(new ShipSelectItem
				{
					Ship = userShip,
					Selected = this.sourceList.Contains(userShip.id)
				});
			}
			list2 = (from i in list2
			orderby !i.Selected, i.Ship.level descending, i.Ship.Type descending
			select i).ToList<ShipSelectItem>();
			this.List = new ObservableCollection<ShipSelectItem>(list2);
		}

		// Token: 0x0600023B RID: 571 RVA: 0x00045D74 File Offset: 0x00043F74
		private void OnChangeCommandExecuted(ShipSelectItem item)
		{
			if (item != null)
			{
				if (item.Selected)
				{
					if (!this.sourceList.Contains(item.Ship.id))
					{
						this.sourceList.Add(item.Ship.id);
						return;
					}
				}
				else if (this.sourceList.Contains(item.Ship.id))
				{
					this.sourceList.Remove(item.Ship.id);
				}
			}
		}

		// Token: 0x040001B3 RID: 435
		private string _mode;
	}
}
